﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using TSL_Tools.SqlTools;
using ReportingEngine;
using System.IO;
using System.Windows.Forms.DataVisualization.Charting;
using System.Xml;
using System.ComponentModel;
using System.Drawing;

namespace VSLT_Reporting
{
    public partial class MainWindow : Window
    {
        #region -- Section for generic charting. Needs some cleanup ----------------------------------------------------------------------------
        private void BuildNewChart(List<int> listOfItemsToAdd, string chartTitle)
        {
            BuildNewChart(listOfItemsToAdd, chartTitle, false);
        }

        private TimeSpan BuildNewChart(List<int> listOfItemsToAdd, string chartTitle, bool copyToEndOfReport)
        {
            DateTime dt = DateTime.Now;
            tsslMessage.Content = String.Format(Msg_TSSL_BUILDING_CHART, chartTitle);

            Chart chart = this.FindName("MyWinformChart") as Chart;
            LoadChartTemplate(ref chart, Properties.Settings.Default.ChartTemplateWithLegendName);
            chart.Titles[0].Text = chartTitle;
            currentPlotColor = 0;

            if(!copyToEndOfReport)
                tabChartControl.IsSelected = true;

            foreach (int x in listOfItemsToAdd)
            {
                AddChartSeriesItems(x);
            }
            int qty = chart.Series.Count;
            chart.Height = chart.Height + (qty * Properties.Settings.Default.Charting_LegendRowHeight);
            if (copyToEndOfReport)
            {
                AddCurrentChartToReport();
            }
            else
            {
                tsslMessage.Content = Msg_TSSL_COMPLETED_CHART;
            }
            return (TimeSpan)(DateTime.Now - dt);
        }

        private void BuildNewChartWithoutLegend(List<int> listOfItemsToAdd, string chartTitle, bool copyToEndOfReport)
        {
            tsslMessage.Content = String.Format(Msg_TSSL_BUILDING_CHART, chartTitle);

            Chart chart = this.FindName("MyWinformChart") as Chart;
            LoadChartTemplate(ref chart, Properties.Settings.Default.ChartTemplateName);
            chart.Titles[0].Text = chartTitle;
            currentPlotColor = 0;

            if (!copyToEndOfReport)
                tabChartControl.IsSelected = true;

            foreach (int x in listOfItemsToAdd)
            {
                AddChartSeriesItems(x);
            }
            if (copyToEndOfReport)
            {
                AddCurrentChartToReport();
            }
            else
            {
                tsslMessage.Content = Msg_TSSL_COMPLETED_CHART;
            }
        }

        private DataTable BuildLegendDataForChart(List<int> listOfItemsToAdd)
        {
            DataTable _table = new DataTable();
            for (int x = 0; x < listOfItemsToAdd.Count; x++)
            {

            }
            return _table;
        }

        private TimeSpan GetIntervalValues(ref TSL_ChartingDataSeries series)
        {
            DateTime dt = DateTime.Now;

            string sqlConn = Properties.Settings.Default.sqlConn;
            string sqlCmd = String.Format(TSL_ReportingEngine.Sql_GETPERFMONCOUNTERSERIES, series.runId, series.instanceId);
            DataTable _tempTable;
            TimeSpan ts = tts.ExecuteReaderTable(sqlCmd, out _tempTable);
            mostRecentSqlQuery = sqlCmd;
            series.testIntervalValues = _tempTable.Copy();

            //AddDebugTimingInfo((TimeSpan)(DateTime.Now - dt), " -- GetIntervalValues");
            return (TimeSpan)(DateTime.Now - dt);
        }
        #endregion

        private void AddGenericTableAndChartToReport()
        {

        }

        private void BuildGenericTimingChart(ref DataTable genericItems)
        {

        }

        private TimeSpan GetGenericChartObjects(ref DataTable testItems)
        {
            DateTime dt = DateTime.Now;

            return (TimeSpan)(DateTime.Now - dt);
        }
    }

}
